﻿@model RH.Web.ViewModels.UtilityModels.ListConfig
@using RH.Common.Extensions;
@{
    ///If no column information specified then default to all columns of the DataTable, with default formating.
    if (Model != null && Model.DataSource != null && Model.DataSource.Rows.Count > 0 && Model.Columns.Count == 0)
    {
        foreach (System.Data.DataColumn column in Model.DataSource.Columns)
        {
            Model.Columns.Add(new Column(column.ColumnName, null));
        }
    }

    //if (!Model.DeleteJsMethod.IsNullOrEmpty() && Model.Columns.Count > 0)
    //{
    //    Column deleteColumn = new Column("Delete", null, Model.DeleteJsMethod, "ID");
    //}
}
@functions{
    //private bool IsExcludedColumn(String columnName, List<String> columnNames)
    //{
    //    if (columnNames.FirstOrDefault(P => String.Compare(columnName, P, true) == 0) != null)
    //        return true;

    //    return false;
    //}
}
@if (Model == null || Model.DataSource.Rows.Count <= 0)
{
    @Html.InfoMessageBox("Sorry! No record found.", "No Record")
}
else
{
    <table class="table table-hover">
        <tr>
            @foreach (var column in Model.Columns)
            {   
                <th>@column.Name</th>
            }
        </tr>
        @foreach (System.Data.DataRow row in Model.DataSource.Rows)
        {
            <tr>
                @foreach (var column in Model.Columns)
                {   
                    <td>
                        @if (column.Method == null) { 
                            @WebUtil.FormatData(row[column.Name])
                        }
                        else
                        {
                            @column.Method(row);
                        }
                    </td>
                }                
            </tr>
        }
    </table>
}